﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace modul3
{
    public static class FunctionsModule3
    {
        public static bool IsValidName(string name) 
        {
            for (int i = 0; i < name.Length; i++)
            {
                if (char.IsSeparator(name[i]))
                {
                    return false;
                }
            }
            return true;
        }

        #region Serialization and desarialization of objects

        public static void StoreSysIndex(SysIndex obj)
        {
            FileStream stream = new FileStream(cConfigModule3.sSysIndexFileName, FileMode.Create);
            BinaryFormatter binary = new BinaryFormatter();
            binary.Serialize(stream, obj);
            stream.Close();
        }

        public static void LoadSysIndex(ref SysIndex obj)
        {
            FileStream stream = new FileStream(cConfigModule3.sSysIndexFileName, FileMode.Open);
            BinaryFormatter binary = new BinaryFormatter();
            obj = binary.Deserialize(stream) as SysIndex;
            stream.Close();
        }

        public static void StoreSysConstr(SysConstr obj)
        {
            FileStream stream = new FileStream(cConfigModule3.sSysConstrFileName, FileMode.Create);
            BinaryFormatter binary = new BinaryFormatter();
            binary.Serialize(stream, obj);
            stream.Close();
        }

        public static void LoadSysConstr(ref SysConstr obj)
        {
            FileStream stream = new FileStream(cConfigModule3.sSysConstrFileName, FileMode.Open);
            BinaryFormatter binary = new BinaryFormatter();
            obj = binary.Deserialize(stream) as SysConstr;
            stream.Close();
        }

        #endregion
    }
}
